<?php if ('print' != $this->view ) {?>
<form method="get" action="/admin/report/">
<p>
            <select  name="id_user" id="id_user">
                <option value="" >Select user</option>
                <?php 
                     foreach ($this->aUser as $oUser)
                     {
                ?>               
                        <option value="<?php echo $oUser->id;  ?>" <?php if (isset($this->user)) echo $this->user->id == $oUser->id ? 'selected="selected"' : ''; ?>><?php echo $oUser->email; ?></option>
                <?php } ?>
            </select>
</p>
<input type="submit" value="View" id="submit" />
</form>

<?php }?>

<?php 

    if (isset($this->allReport))
    {
    	$allReport    = $this->allReport;
    	$all_overtime = $all_total = 0;
?>
   <br /> <br />
   
 <table border="0">
    <tr>
        <th>Name:</th>
        <th> &nbsp; <?php echo $this->user->name; ?> &nbsp;</th>
        <th> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </th>
        <th> &nbsp; Afkorting: &nbsp;</th>
        <th> &nbsp; <?php echo $this->user->afk; ?> &nbsp;</th>
        <th> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </th>
        <th> &nbsp; Periode: &nbsp; </th>
        <th> &nbsp; <?php echo $this->period; ?> &nbsp; </th>
        <th> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </th>
        <th> &nbsp; <?php echo 'print' == $this->view ? '' : 'View:' ?> &nbsp; </th>
        <th> 
            &nbsp;  
            <?php if ('print' != $this->view) { ?>
            <select name="archive" id="archive" <?php echo 'print' == $this->view ? 'readonly="readonly" disabled="disabled"' : '' ;?>>
            <option name="">Current month</option>
            <?php
                foreach ($this->archiveDate as $date)
                {
                    $select = $this->archive == $date ? 'selected="selected"' : '';
                    echo '<option name="' . $date . '" ' . $select . '>' . $date .'</option>' . "\n";
                } 
            ?>
            </select>
            <?php } ?>
            &nbsp; 
         </th>
        
        <input type="hidden" id="year" value="<?php echo $this->year; ?>" />
        <input type="hidden" id="month" value="<?php echo $this->month; ?>" />
    </tr>
 </table>
    
    <br /> <br />
       
 <table border="1" class="table_with_border" <?php echo 'print' == $this->view ? 'width="90%"' :'' ?>>   
    <tr class="border2">
        <th>
        </th>
        <?php for($i = 1; $i <= $this->endDay; $i++)
        {
        ?>
        <th class="project_name <?php if (
            6 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i)) || 
            0 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i))) 
            echo 'pink';?>"> <?php echo date('D', strtotime($this->year . '-' .  $this->month . '-' . $i)); ?> </th>
        <?php 
        }
        ?>
    </tr>
    
    <tr class="border2">
        <th>
        </th>
        <?php for($i = 1; $i <= $this->endDay; $i++)
        {
        ?>
        <th  class="<?php if (
            6 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i)) || 
            0 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i))) 
            echo 'pink';?>"><?php echo $i; ?></th>
        <?php 
        }
        ?>
        <th class="project_name"> Totaal </th>
    </tr>    
    <?php 
//    print_r($this->allProject);
        foreach($this->allProject as $project)
        {
        	$tr = 0;
//              print_r($project);
    ?>
    <tr class="border2">
        <td class="project_name">
            <?php echo $project['name']; ?>
        </td>
            <?php for($i = 1; $i <= $this->endDay; $i++)
            {
                if ((1 != $project['base']))
                {   
                    $aStartDate       = explode('-', $project['start_date']);
                    (int) $startDay   = $aStartDate[2];
                    
                    $aEndDate         = explode('-', $project['end_date']);
                    (int) $endDay     = $aEndDate[2];
                    
                    if($aStartDate[1] != $aEndDate[1])
                    {
                        $endDay   = $this->endDay;
                    }
                }
                else
                {
                    $startDay = 1;
                    $endDay   = $this->endDay;
                }   
                
            ?>
        <td  class="<?php if (
            6 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i)) || 
            0 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i))) 
            echo 'pink';?>"><?php
               if (($i >= $startDay && $i <= $endDay) || (1 == $project['base'])) 
               {
                   $val = '';
                   if (isset($allReport[$i]))
                   {
                       if (isset($allReport[$i][$project['id']]))
                       {
                           $val = $allReport[$i][$project['id']] ;
                       }
                   }       
                   echo  '&nbsp;' . $val . '&nbsp;';
                   if (isset($total[$i]))
                        $total[$i] += $val;
                   else
                        $total[$i] = $val;
                        
                   $tr += $val;     
               } 
            ?>
        </td>
            <?php 
            }
            ?>
            
        <td class="project_name">&nbsp;<?php echo number_format($tr, 1, '.', ''); ?></td>    
            
    </tr>
    <?php 
        }
    ?>
    
        <tr class="border2">
        <td></td>
            <?php for($i = 1; $i <= $this->endDay; $i++)
            {
            
            ?>
        <td  class="<?php if (
            6 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i)) || 
            0 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i))) 
            echo 'pink';?>"><?php

                   echo '&nbsp;';
            ?>
        </td>
            <?php 
            }
            ?>
    </tr>
    
    <tr class="border2">
        <td class="project_name">Normal hours: </td>
            <?php 
            for($i = 1; $i <= $this->endDay; $i++)
            {
            
            ?>
        <td  class="project_name <?php if (
            6 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i)) || 
            0 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i))) 
            echo 'pink';?>"> &nbsp; <?php

                   $ct =  $total[$i] <= 8 ? $total[$i] != 0 ? $total[$i] : '' : 8;
                   echo number_format($ct, 1, '.', '');
                   $all_total += $ct;
            ?> 
        </td>
            <?php 
            }
            ?>
        <td class="project_name"> &nbsp; <?php echo number_format($all_total, 1, '.', ''); ?></td>
    </tr>
    
    <tr class="border2">
        <td class="project_name">Overtime: </td>
            <?php for($i = 1; $i <= $this->endDay; $i++)
            {
            
            ?>
        <td  class="project_name <?php if (
            6 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i)) || 
            0 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i))) 
            echo 'pink';?>"> &nbsp; <?php

                   $cot =   $total[$i] > 8 ? $total[$i] - 8 : '';
                   echo number_format($cot, 1, '.', '');
                   $all_overtime += $cot;
            ?> 
        </td>
            <?php 
            }
            ?>
        <td class="project_name"> &nbsp; <?php echo number_format($all_overtime, 1, '.', ''); ?></td>
    </tr>
    
    <tr class="border2">
        <td class="project_name">Totals: </td>
            <?php 
            $all_total = 0;
            for($i = 1; $i <= $this->endDay; $i++)
            {
            
            ?>
        <td  class="project_name <?php if (
            6 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i)) || 
            0 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i))) 
            echo 'pink';?>"> &nbsp; <?php

                   $ct =  $total[$i] ;
                   echo number_format($ct, 1, '.', '');
                   $all_total += $ct;
            ?> 
        </td>
            <?php 
            }
            ?>
        <td class="project_name"> &nbsp; <?php echo number_format($all_total, 1, '.', ''); ?></td>
    </tr>
</table>    
    
    <br /><br />

<div class="clear"></div>
<?php  if ('print' == $this->viewss) 
{ ?>
<div class="grid_1 alpha omega"> &nbsp; </div>
<?php } ?>
<div class="grid_3 alpha omega border2">Handtekening medewerker: <br /><br /><br /><br /></div>
<?php //if ('print' == $this->view) 
{ ?>
<div class="grid_1 alpha omega"> &nbsp; </div>
<?php } ?>
<div class="grid_3 alpha omega border2">Handtekening opdrachtgever: <br /><br /><br /><br /></div>
<?php //if ('print' == $this->view) 
{ ?>
<div class="grid_1 alpha omega"> &nbsp; </div>
<?php } ?>
<div class="grid_<?php echo 'print' == $this->view ? '3' : '2'?> alpha omega border2">Opmerkingen: <br /><br /><br /><br /></div>

<div class="clear"></div>
<br /><br /><br />
    
 <?php if ('print' != $this->view ) {?>   
    <table border="0">
    <tr><td class="project_name"> 
	    <form action="/admin/report/" method="post">
	        <input type="hidden" name="id_user" value="<?php echo $this->user->id; ?>" />
	        <input type="hidden" name="view" value="print" />
            <input type="hidden" name="year" value="<?php echo $this->year; ?>" />
            <input type="hidden" name="month" value="<?php echo $this->month; ?>" />   
            <input type="hidden" name="archive" value="<?php echo $this->archive; ?>" />
	        <input type="submit" class="sexybutton sexysimple sexygreen " value="Print report" /> 	
	    </form>	
	    </td><td class="project_name">
	    <form action="/admin/report/period" method="post">
	        <input type="hidden" name="id_user" value="<?php echo $this->user->id; ?>" />
	        <input type="hidden" name="do_action" value="<?php echo 'close' == $this->reportPeriod['status'] ? 'open' : 'close'?>" />
	        <input type="hidden" name="year" value="<?php echo $this->year; ?>" />
	        <input type="hidden" name="month" value="<?php echo $this->month; ?>" />          
	        <input type="submit" class="sexybutton sexysimple <?php echo 'close' == $this->reportPeriod['status'] ? 'sexyred' : 'sexygreen'?>"  value="<?php echo 'close' == $this->reportPeriod['status'] ? 'Open' : 'Close'?> period" />   
	    </form> 
 
        </td>
        <?php 
            if (isset($this->attach))
            {
        ?>
             <td class="project_name">  
                <a href="/attach/<?php echo $this->attach['file_name']?>" target="_blank" class="sexybutton sexysimple sexygreen">View timesheet</a>
             </td>
        <?php 
            }?>
	 </tr>
     <tr>
     <td colspan="3" class="project_name">  
        <form action="/admin/report/attach" enctype="multipart/form-data" method="post">
            <input type="hidden" name="id_user" value="<?php echo $this->user->id; ?>" />
            <input type="hidden" name="do_action" value="attach" />
            <input type="hidden" name="year" value="<?php echo $this->year; ?>" />
            <input type="hidden" name="month" value="<?php echo $this->month; ?>" />
            <input type="file"   name="file_name" id="file_name" maxlength="255"  />          
            <input type="submit" class="sexybutton sexysimple sexygreen"  value="Attach timesheet" />   
        </form> 
     </td>
     </tr>
   </table> 
 <?php }else { ?>

<script type="text/javascript">
$(function()
{
    window.print();
});
</script>

 <?php }?>   
<?php     	
    }